/**
 * Copyright (c) 2022 Yansen Zhang
 * wxcomponent is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
**/

package authorization

import (
	"encoding/xml"
)

// VerifyTicketResult 获取验证票据结果
type VerifyTicketResult struct {
	AppId                 string `xml:"AppId"`
	CreateTime            int64  `xml:"CreateTime"`
	InfoType              string `xml:"InfoType"`
	ComponentVerifyTicket string `xml:"ComponentVerifyTicket"`
}

// ParseVerifyTicket 获取验证票据
// data 是解密之后的数据
func ParseVerifyTicket(data []byte) (*VerifyTicketResult, error) {
	res := VerifyTicketResult{}

	if e := xml.Unmarshal(data, &res); e != nil {
		return nil, e
	}

	return &res, nil
}
